package com.lu.article.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lu.article.mapper.ApArticleConfigMapper;
import com.lu.article.service.ApArticleConfigService;
import com.lu.model.article.pojo.ApArticleConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

@Slf4j
@Service
@Transactional
public class ApArticleConfigServiceImpl extends ServiceImpl<ApArticleConfigMapper, ApArticleConfig> implements ApArticleConfigService {


    /**
     * App端文章通知上下架
     * @param map
     */
    @Override
    public void updateByMap(Map map) {
        if (map != null) {
            //enable的上下架数值和isdown相反
            boolean flag = true;
            Object enable = map.get("enable");
            if (enable.equals(1)) {
                flag = false;
            }
            this.update(Wrappers.<ApArticleConfig>lambdaUpdate().eq(ApArticleConfig::getArticleId, map.get("articleId")).set(ApArticleConfig::getIsDown, flag));

        }
    }
}
